package mysql

import "gorm.io/gorm"

type Comment struct {
	gorm.Model
	UserId   int    `gorm:"type:tinyint;not null;comment:用户ID"`
	CourseId int    `gorm:"type:tinyint;not null;comment:课程ID"`
	Content  string `gorm:"type:varchar(35);not null;comment:评论内容"`
	Score    int    `gorm:"type:int(1);not null;comment:分数"`
}

func (c *Comment) AddComment() error {
	return DB.Create(&c).Error
}

func (c *Comment) CommentList(userId int) (comment []Comment, err error) {
	err = DB.Where("user_id = ?", userId).Find(&comment).Error
	return comment, err
}
